package Thread;

public class ThreadDemo18 {
    public static void main(String[] args) {

        Object o = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (o) {
                System.out.println("线程t1 wait 之前");
                try {
                    o.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程t1 wait 之后");
            }
        });

        Thread t2 = new Thread(() -> {
            try {
                // 让t2先休眠2s，保证t1线程先wait
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            synchronized (o) {
                System.out.println("线程t2 notify 之前");
                o.notify();
                System.out.println("线程t2 notify 之后");
            }
        });

        t1.start();
        t2.start();
    }
}
